<% extends "common/msui.html" %>
<% block title %>我的<% endblock %>
<% block body %>
<div class="page" id='my_account' ms-controller="my_account">

  <div class="content">
    <a href='/mshop/my/info?partner_id=${partner_id}'>
      <div class='my-picture' >
        <img id='image' src='/website/image/res.partner/${partner_id}/image' />
        <div>{{name}}</div>
      </div>
    </a>

    <div class='my-order'>
      <div class='my-order-all'>
        <span>全部订单</span><span ><a href='/mshop/order'>查看全部订单 ></a></span>
      </div>

      <hr />
      <div class='my-order-list'>
        <ul>
          <li><a href='/mshop/order?state=draft'><span class='icon icon-edit'></span><span>待确认({{counts.confirm_count}})</span></li></a>
          <!-- <li><a href='/mshop/order?state=confirmed'><span class='icon icon-card'></span><span>已确认</span></li></a> -->
          <!-- 似乎暂时没有状态可以区分不同单据的付款去发货状态 -->
          <li><a href='/mshop/order?state=progress,manual'><span class='icon icon-gift'></span><span>待收货({{counts.stock_count}})</span></li></a>
          <li><a href='/mshop/order?state=done'><span class='icon icon-message'></span><span>待评价({{counts.evaluation_count}})</span></li></a>
        </ul>
      </div>
    </div>

    <div class='my-order-address'>
      <span>默认地址</span>
      <hr>
      <div class='media-list list-block order-address' >
        <a href="/mshop/customer/address" class="item-link item-content order-address-content">
          <div class="item-inner">
            <div class="item-title-row">
              <div class="item-title"><span>收货人：</span>{{address.name}}</div>
              <div class="item-after">{{address.phone}}</div>
            </div>
            <div class='item-text'><span>{{address.province}}{{address.city}}{{address.country}} {{address.street}}</span></div>
          </div>
        </a>
      </div>
    </div>
  </div>

  <footer>
    <nav class="bar bar-tab index-footer">
      <a class="tab-item" href="/mshop?tab=index">
        <span class="icon icon-home"></span>
        <span class="tab-label">首页</span>
      </a>
      <a class="tab-item" href="/mshop?tab=cart">
        <span class="icon icon-cart"></span>
        <span class="tab-label">购物车</span>
      </a>
      <a class="tab-item" href="/mshop?tab=my">
        <span class="icon icon-me"></span>
        <span class="tab-label">我的</span>
      </a>
    </nav>
  </footer>
  
<script type="application/javascript">

  $(function() {
      var partner_id = ${partner_id | safe};

      var sync_content = function() {
          $.ajax({
              url: '/mshop/my/get',
              data: {
                  'partner_id': partner_id
              },
              success: function(e) {
                  var res = JSON.parse(e);
                  my_vm.name = res.name;
                  my_vm.address = res.address;
                  my_vm.counts = res.counts;
              },
              type: 'GET',
              async: true,
          });
      };

      sync_content();

      var my_vm = avalon.define({
          $id: 'my_account',
          name: '',
          address: {},
          counts: {},
      });

      $(document).on('pageReinit', '#my_account', function(e, pageId, $page) {
          sync_content();
      });

      avalon.scan();
  });

</script>
<% endblock %>
</div>